/**
 * rege folder
 * http://regesystems.com/
 * Released into the public domain
 * Date: Mar.12th 2009
 * @author Johnason
 * @version 1.0
 *
 *   
 * @example $('selector').regeFolder({id:'mywin', width:"200", height:"300"});
 *  
 */
jQuery.fn.regeFolder = function(props) {
	props = jQuery.extend({
	}, props); 

	return $(this).each(
	  function() {
		  var folderId = "regeFolder"+Math.round(Math.random()*100);
		  //var insidehtml = $(this).html();
		  
		  var navBtns = '<div class="nav-most-right-btn bg-fix-png"><div class="nav-label"><a href="#content-regesytems">REGeSystems</a></div></div>';
		  var navContents = '<div class="tab-content" id="content-regesytems"><h1>REGeSystems.Inc</h1></div>';
		  var colorLabels = +'<div class="color-label lab1">A</div>'
							+'<div class="color-label lab2">B</div>'
							+'<div class="color-label lab3">C</div>';
		  var bottomLabel = '';
		  
		  var liLength =  $(this).find('ul.nav-buttons li').length;
		  if ( liLength>0 ){
			  navBtns = '';
			  $(this).find('ul.nav-buttons li').each(function( i, dom ){
				  var rx = 154;
				  if ( i == liLength-1 ){
					  navBtns += '<div class="nav-most-right-btn bg-fix-png"><div class="nav-label">'+$(this).html()+'</div></div>';
				  }else{
					  var right = rx+ 134*(liLength-2-i);
					  navBtns += '<div class="nav-btn bg-fix-png" style="right:'+right+'px;"><div class="nav-label">'
					  			 +$(this).html()
					  			 +'</div></div>';
				  }
			  });
		  }
		  if ( $(this).find('.tab-contents').length>0 ){
			  navContents = $(this).find('.tab-contents').html();
		  }
		  if ( $(this).find('.color-labels').length>0 ){
			  colorLabels = $(this).find('.color-labels').html();
		  }
		  
		  if ( $(this).find('.bottom-label').length>0 ){
			  bottomLabel = $(this).find('.bottom-label').html();
		  }
		  
		  // avoid name conflict
		  var newhtml = '<div class="rege-folder" id="'+folderId+'">'
						+'<div class="nav-bar">'
						+ navBtns
						+'<div class="nav-bar-right-border bg-fix-png"></div>'
						+'</div>'
						+'<div class="foler-top">'
						+'<div class="f-nw bg-fix-png"></div>'
						+'<div class="f-ncen-left bg-fix-png"></div>'
						+'<div class="f-ncen bg-fix-png"></div>'
						+'<div class="f-ncen-right bg-fix-png"></div>'
						+'<div class="f-ne bg-fix-png"></div>'
						+'</div>'
						
						+'<div class="foler-mid">'
						+'	<div class="f-mid-w bg-fix-png"></div>'
						+'	<div class="f-mid-cen">'
						+ navContents
						+'</div>'
						+'<div class="f-mid-e"></div>'
						+'</div>'
						
						+'<div class="foler-bot">'
						+'	<div class="f-sw bg-fix-png"></div>'
						+'	<div class="f-scen bg-fix-png">' 
						+ bottomLabel
						+'	</div>'
						+'	<div class="f-se bg-fix-png"></div>'
						+'</div>'
						
						+ colorLabels
						+'</div>';
		  //alert( newhtml );
		  $(this).html( newhtml );
		  $(this).width( 608 );
		  
		  $('.nav-btn,.nav-most-right-btn').mouseover(function(){
			  $('#'+folderId+" div.nav-label").removeClass( 'label-hover' );
			  $('#'+folderId+' .tab-content').hide();
			  var label = $(this).children('div.nav-label');
			  var href = label.children('a').attr('title');
			  label.addClass( 'label-hover' );
			  $(href).show();
		  });
		  
		  $('.nav-btn,.nav-most-right-btn').click(function(){
			  var href = $(this).find('a').attr('href');
			  window.open( href, '_self');
		  });
		  
		  // Path to a transparent GIF image
		  var shim = 'script/regeWindow/blank.gif';
		  var bg_fnFixPng = function(obj) {
			var mode = 'scale';
			var bg	= obj.currentStyle.backgroundImage;
			var src = bg.substring(5,bg.length-2);
			if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
				mode = 'crop';
			}
			obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
			obj.style.backgroundImage = 'url('+shim+')';
		  };
		  
		  if($.browser.msie && (jQuery.browser.version.substr(0,1)< "7")){
			  $('#'+folderId+' .bg-fix-png').each(function(){
				  bg_fnFixPng(this);
			  });
		  }
		  
	  });
};
